import Vue from 'vue'
import VueRouter from 'vue-router'
import login from '../views/Login.vue'
import home from '../views/Home.vue'

/* 洗车订单 */
import indent_wash from '../views/Indent_wash.vue'
/* 维修订单 */
import indent_repair from '../views/Indent_repair.vue'
/* 保养订单 */
import indent_upkeep from '../views/Indent_upkeep.vue'
/* 评价管理 */
import indent_comment from '../views/Indent_comment.vue'

// 引入服务管理组件
import service from '../views/Service.vue'
// 引入服务类别组件
import servicetype from '../views/Servicetype.vue'
import welcome from '../views/Welcome.vue'
import user from '../views/User.vue'
import notice from '../views/Notice.vue'
import noticeNoCheck from '../views/NoticeNoCheck.vue'
import noticeCheck from '../views/NoticeCheck.vue'
import rescue from '../views/Rescue.vue'

// 商户管理
import Merchantmanage from '../views/MerchantManagement.vue'
import MerchantXQ from '../views/MerchantXQ.vue'
import Merchantrank from '../views/MerchantRanking.vue'

import systemUser from '../views/SystemUser.vue'
import stytemMenus from '../views/SystemMenus.vue'
import systemRole from '../views/SystemRole.vue'
import dictionary from '../views/Dictionary.vue'



Vue.use(VueRouter)
const routes = [
	// 配置默认访问的请求转发到login请求中
	{
		path: '/',
		redirect: '/login'
	},
	// 当访问login请求时，直接把login组件展示给前端
	{
		path: '/login',
		component: login
	},
	{
		// home是主组件,service是子组件
		path: '/home',
		component: home,

		
		children: [
			{path:'/indent_wash',component:indent_wash},
			{path:'/indent_repair',component:indent_repair},
			{path:'/indent_upkeep',component:indent_upkeep},
			{path:'/indent_comment',component:indent_comment},
			{
				path: '/service',
				component: service
			},
			{
				path: '/user',
				component: user
			},
			{
				path: '/notice',
				component: notice
			},
			{
				path: '/noticeNoCheck',
				component: noticeNoCheck
			},
			{
				path: '/noticeCheck',
				component: noticeCheck
			},
			{
				path: '/rescue',
				component: rescue
			},
			{
				path: '/servicetype',
				component: servicetype

			},
			
			
			{
				path:'/Merchantmanage',
				component:Merchantmanage
			},
			{
				path:'/MerchantXQ',
				component:MerchantXQ
			},
			{
				path:'/Merchantrank',
				component:Merchantrank
			},

			{

				path: '/systemUser',
				component: systemUser

			},
			{
				path: '/systemRole',
				component: systemRole
			}, 
			{
				path: '/dictionary',
				component: dictionary
			},
			{
				path: '/welcome',
				component: welcome

			}

			,
			{
				path: '/systemMenus',
				component: stytemMenus

			},
			{
				path: '/dictionary',
				component: dictionary

			}
		]
	}


]

const router = new VueRouter({
	routes
})

// 添加路由守卫，来设置拦截保证前端必须登录后才能访问的请求
router.beforeEach((to, from, next) => {
	if (to.path === '/login') { // 如果请求是登录，则释放
		return next();
	}
	// 如果不是登录页面，则需要判断sessionStorage中是否有数据
	let tokenstr = window.sessionStorage.getItem('token');
	if (!tokenstr) { // 没有数据
		alert("请先登录！")
		return next('/login');
	}
	// token有数据，则为登录后的情况，则释放即可
	next();
})

export default router